<?php
	require_once('include/menu.class.php');
	require_once('include/user.class.php');
	require_once('include/database.class.php');
	$menu = Menu::create();
	$db = new Database();
	User::start();
	$listOfUsers = $db->query("SELECT * FROM uzytkownicy;");
	echo '<?xml version="1.0" encoding="UTF-8"?>';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="pl">
<head>
	<title>Baza danych obiektów turystycznych</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<link rel="icon" type="image/png" href="images/photos.png">
	<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
	<?php
		echo $menu;
	?>
	<?php
		if(false)
		{
			?>
				<div id="success-listing">
				<ul>
			<?php
				
			?>
				</ul>
				</div>
			<?php
		}
		if(!User::isAdmin())
		{
			?>
				<div id="error-listing">
				<ul>
			<?php
				if(!User::isAdmin()) echo '<li>Nie jesteś administratorem!</li>';
			?>
				</ul>
				</div>
			<?php
		}
		if(User::isAdmin())
		{
	?>
	<div id="admin-container">
		<h3><img src="images/group.png" /> Użytkownicy</h3>
		<div id="users-list">
		<table>
		<thead><th>Login</th><th>Imię</th><th>Nazwisko</th><th>E-mail</th><th>Admin?</th></thead>
		<?php
			foreach($listOfUsers as $listedUser)
			{
				echo '<tr>';
				echo '<td>'.$listedUser['login'].'</td>';
				echo '<td>'.$listedUser['imie'].'</td>';
				echo '<td>'.$listedUser['nazwisko'].'</td>';
				echo '<td>'.$listedUser['mail'].'</td>';
				echo '<td>'.($listedUser['czy_admin'] == 't' ? '<img src="images/user_gray.png"/>' : '<img src="images/user.png"/>').'</td>';
			}
		?>
		</table>
		</div>
		<h3><img src="images/user_gray.png" /> Nowy administrator</h3>
		<div id="new-user">
		<form method="post" action="adduser.php">
			Login:<br/><input type="text" name="login" /><br/>
			Hasło:<br/><input type="password" name="pass" /><br/>
			Imię:<br/><input type="text" name="imie" /><br/>
			Nazwisko:<br/><input type="text" name="nazwisko" /><br/>
			E-mail:<br/><input type="text" name="mail" /><br/>
			<input type="submit" name="submit" value="Dodaj administratora" />
		</form>
		</div>
	</div>
	<?php
		}
	?>
</body>
</html>